package com.tanhua.server.controller;

import cn.hutool.core.collection.CollUtil;
import com.tanhua.model.mongo.Answer;
import com.tanhua.model.vo.ReportVo;
import com.tanhua.model.vo.SoulPaperVo;
import com.tanhua.server.service.SoulPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class SoulPaperController {

    @Autowired
    private SoulPaperService soulPaperService;

    @GetMapping//查询试卷列表
    public ResponseEntity findSoul(){
        //1.前端没有传递参数
        //2.调用service进行处理
        List<SoulPaperVo> vos =soulPaperService.findSoul();
        //3.返回参数
        return ResponseEntity.ok(vos);
    }

    @PostMapping//提交测试题
    public ResponseEntity submitTheAnswer(@RequestBody Map<String,List<Answer>> map){
        //1.从前端接收一个集合类型的参数
        List<Answer> answers = map.get("answers");
        //2.调用service处理
        String id=soulPaperService.submitTheAnswer(answers);
        //3.前端需要返回一个报告id
        return ResponseEntity.ok(id);
    }


    @GetMapping("/report/{id}")//查看测试报告
    public ResponseEntity report(@PathVariable("id")String reportId){
        //1.接收参数,前端传递回来一个报告id
        //2.调用service处理
        ReportVo reportVo= soulPaperService.findReport(reportId);
        //3.这里其实应该有个vo对象要返回，先不填
        return ResponseEntity.ok(reportVo);
    }
}
